﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Controls.Classes;
using Silvermoon.Controls.Panoramic;
using System.Collections.ObjectModel;

namespace Silvermoon.Controls
{
    public class PanoramaSectionCollection : Collection<PanoramaSection>
    {
        const int maxSections = 5;
        private INotifyPanoramaSectionChanged panorama;

        public PanoramaSectionCollection(Panorama panorama)
            : base()
        {
            this.panorama = panorama;
        }

        protected override void InsertItem(int index, PanoramaSection item)
        {
            if (Count > maxSections) throw new IndexOutOfRangeException("Number of allowed sections exceeded.");
            base.InsertItem(index, item);
            panorama.SectionAdded(item);
        }

        protected override void RemoveItem(int index)
        {
            PanoramaSection c = this[index];
            base.RemoveItem(index);
            panorama.SectionRemoved(c);
        }

        protected override void ClearItems()
        {
            base.ClearItems();
            panorama.CollectionCleared();
        }

    }
}
